Skip to content

Remove leftover ZEND_CAST code for (unset) cast. #5042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

TysonAndre
Copy link
Contributor

@TysonAndre TysonAndre commented Dec 30, 2019

Followup for d74d392

Attempting to require a file with (unset) casts results in an E_COMPILE_ERROR
that can't be caught or handled by set_exception_handler/set_error_handler.

Also remove the _IS_BOOL handlers, because the ZEND_BOOL opcode handles that (emitted by zend_compile.c).

Remove inference that array -> object cast can throw.
It was added in 2a286ad - I don't know how creating an stdClass would throw.
(numeric keys, references, etc. don't cause it to throw, and out of memory would be a fatal error)

  • It looks like a separate opcode would free the original arg, even for $x = (object)$x. (ZEND_CAST then ZEND_ASSIGN).

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG with nits.

@@ -5730,12 +5730,6 @@ ZEND_VM_COLD_CONST_HANDLER(51, ZEND_CAST, CONST|TMP|VAR|CV, ANY, TYPE)
expr = GET_OP1_ZVAL_PTR(BP_VAR_R);

switch (opline->extended_value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an assert along the lines of ZEND_ASSERT(opline->extended_value != _IS_BOOL && "Must use ZEND_BOOL instead"); here.

Copy link
Contributor Author

@TysonAndre TysonAndre Jan 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ZEND_ASSERT(opline->extended_value == IS_OBJECT); I added would also fail for that same assertion, just later in the program execution. There weren't any early returns I saw.

Added anyway to default:

@@ -106,6 +106,7 @@ static inline zend_bool may_have_side_effects(
case ZEND_IS_SMALLER:
case ZEND_IS_SMALLER_OR_EQUAL:
case ZEND_CASE:
/* TODO: Can ZEND_CAST throw when converting object to array (in custom handlers for zend_get_properties_for?) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say yes. Throwing is not handled by this function though, but by zend_may_throw.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed comment

@@ -4630,8 +4605,9 @@ int zend_may_throw(const zend_op *opline, const zend_op_array *op_array, zend_ss
case IS_ARRAY:
return (t1 & MAY_BE_OBJECT);
case IS_OBJECT:
return (t1 & MAY_BE_ARRAY);
return 0;
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with EMPTY_SWITCH_DEFAULT_CASE().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Followup for d74d392

Attempting to require a file with (unset) casts results in an E_COMPILE_ERROR
that can't be caught or handled by set_exception_handler/set_error_handler.

Also remove the (bool) cast, because the ZEND_BOOL opcode handles that.

Remove inference that array -> object cast can throw.
It was added in 2a286ad - I don't know how creating an stdClass would throw.
(numeric keys, references, etc. don't cause it to throw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants